var res [][]int

func combinationSum3(k int, n int) [][]int {
    res = make([][]int, 0)
    if k <= 0 || n <= 0 || k > 9 || n > 45{
        return res
    }
    backTracking(n, k, 1, 0, []int{})
    return res
}

func backTracking(n, k, startIndex, sum int, path []int){
    if len(path) > k {
        return
    }
    if len(path) == k && sum == n {
        tem := make([]int, k)
        copy(tem, path)
        res = append(res, tem)
        return 
    }
    for i:=startIndex; i<=9-(k-len(path))+1; i++ {
        path = append(path, i)
        sum += i
        backTracking(n, k, i+1, sum, path)
        path = path[:len(path)-1]
        sum -= i
    }
}